<? 

	$title="My History";
	require("required/dbconnect.php");
	require("required/share_function.php");
	$_SESSION['pid']=-1;
	require("required/header.php");
	require("required/chkuser.php");  
	require("required/function.php");  
	

	
	$get_bill=mysql_query("select * from os_bill_details where uid=$member_id and status>=6 order by create_date desc")or die(mysql_error());
	$count=mysql_num_rows($get_bill);

?>

			
				<table width="100%" cellpadding="6" cellspacing="0">
					<td align="left" class="page_title_bar" width="100%">
					 My history
					</td>
					
					<tr>
						<Td height="400" valign="top"><font class="page_description">An archive that shows all of your successful purchases.</font>
							<br /><br />
                            <table width="100%">
							<?	
								if($count==0)
								{
							?>
								<tr>
									<td align="center"> :: NO RECORD :: </td>
								</tr>
							<?	
								}
								else
								{
							?>
							<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
							<tr>
								<td>
								<table width="90%" bgcolor="#CCCCCC" cellpadding="1" cellspacing="1">
								 <tr class="table_header"align="center">
									<td width="19%">Order number</td><td width="21%">Order date</td><td width="21%">Received date</td><td width="22%">Receiver</td><td width="17%">Total amount </td>
								</tr>
							<?
									$no=1;
									while($c=mysql_fetch_array($get_bill))
									{
										if(dayDiff($c['create_date'])>7 and $c['status']<=2)
										{
											$update_expired=mysql_query("update os_bill_details set status='-1' where id=".$c['id']);
										}
										else
										{	
											$total_amount=$c['transport_fees']+$c['total_amount']; 
											$discount=($c['discount']/100)*$total_amount;
											$final_amount=$total_amount-$discount;
											
											$get_voucher=mysql_query("select * from os_discount_voucher_used where bill_id=".$c['id'])or die(mysql_error());
											if(mysql_num_rows($get_voucher)>0)
											{
												$voucher=mysql_query("select * from os_discount_voucher where id='".mysql_result($get_voucher,0,"voucher_id")."'")or die(mysql_error());
												$v=mysql_fetch_array($voucher,MYSQL_ASSOC);
											
												if($v['discount_type']=="P")
												{
													$discount=($total_allprice*$v['discount_amount'])/100;
													$final_amount=$final_amount-$discount;
												}
												else
												{
													$discount=$v['discount_amount'];
													$final_amount=$final_amount-$v['discount_amount'];
												}							
											}	
											
											if($no%2==0)
											{
												$class1="table_item_even";
												$class2="table_item_odd";
											}
											else
											{
												$class1="table_item_odd";
												$class2="table_item_even";
											}																
																				
							?>
								 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" onmouseout="this.className='<?= $class1 ?>'" align="center">
									
									<td><a href="os_closedbill.php?id=<?= $c['id'] ?>"><?= $c['invoice_number'] ?></a></td><td><?= date("Y-m-d",strtotime($c['create_date'])) ?></td>
                                    <td><?= $c['goods_received_date'] ?></td><td><?= $c['receiver_name'] ?></td>
									<td><font color="#FF0000"><?= number_format($final_amount,2) ?></font></td>
								</tr>
							<? 	
										}
								
									} 
							?>
								</table>
								</td>
							</tr>
							
							</form>
							<?
								}
							?>
							</table>
							
						</Td>
					</tr>		  
			  	</table>
			
<? require("required/footer.php"); ?>	